<?php

/************************************

EasyCB, Community Forum Software
Copyright (C) 2007  Jonathon D. Keogh <jonathon.keogh@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

$Id: page.register.php 115 2007-09-05 23:02:37Z jonathon.keogh $

************************************/

// Get our functions
require "inc.func.php";

page_header("Register to " . config_get("BoardName"));

page_section("Register");
?>
To register on this forum, enter your information in to the below fields. All fields are required.
<?php
page_section();

page_section("Board rules");
?>
<b>Please note, these rules can be changed at any time without notice. Please obey them and keep checking here for any changes.</b><br>
<?=nl2br(config_get("BoardRules")) ?>
<?php
page_section();

print "<form action=\"" . htmlentities($_SERVER['PHP_SELF']) . "\" method=\"POST\">\n";

$_name = "";
$_email = "";
$_username = "";

if(isset($_POST['username']))
{
	$_name = trim($_POST['name']);
	$_email = trim($_POST['email']);
	$_username = trim($_POST['username']);
	$_password1 = $_POST['password1'];
	$_password2 = $_POST['password2'];
	
	if($_name == "" || $_email == "" || $_username == "" || $_password1 == "")
	{
		$error = "All fields are required";
	} elseif(User_Exists($_username)) {
		$error = "User name is in use";
	} elseif(strlen($_username) > 50) {
		$error = "User name is too long";
	} elseif(strlen($_email) > 70) {
		$error = "E-mail address is too long";
	} elseif(str_replace("@", "", $_email) == $_email) {
		$error = "E-mail address is not valid";
	} elseif($_password1 != $_password2) {
		$error = "Password and password confirmation entered do not match";
	} elseif(strtolower($_username) == strtolower(config_get("UnknownUser"))) {
		$error = "User name is disallowed by configuration";
	} else {
		db_query("INSERT INTO `" . config_get("db_prefix") . "users` (`Username`, `Password`, `Name`, `Email`, `RegisterTime`, `RegisterIP`, `LastSeenTime`, `LastSeenIP`) VALUES ('" . db_escape($_username) . "', '" . md5($_password1) . "', '" . db_escape($_name) . "', '" . db_escape($_email) . "', '" . time() . "', '" . db_escape($_SERVER['REMOTE_ADDR']) . "', '" . time() . "', '" . db_escape($_SERVER['REMOTE_ADDR']) . "');");
		config_set("UserCount", config_get("UserCount") + 1);
		page_redirect("static.register.php");
	}
}

if(isset($error))
{
	page_section("An error occured");
	print "<b style=\"color: #FF0000;\">$error</b>";
	page_section();
}

page_section("Your registration");
?>

<table width="100%" cellspacing="0" cellpadding="5">
	<tr>
		<td width="200" valign="top" align="right">Your name:</td>
		<td valign="top"><input name="name" size="40" value="<?=htmlentities($_name) ?>"></td>
	</tr>
	<tr>
		<td width="200" valign="top" align="right">E-mail address:</td>
		<td valign="top"><input name="email" size="40" value="<?=htmlentities($_email) ?>"></td>
	</tr>
	<tr>
		<td width="200" valign="top" align="right">Preferred user name:</td>
		<td valign="top"><input name="username" size="40" value="<?=htmlentities($_username) ?>"></td>
	</tr>
	<tr>
		<td width="200" valign="top" align="right">Password:</td>
		<td valign="top"><input name="password1" size="40" type="password"></td>
	</tr>
	<tr>
		<td width="200" valign="top" align="right">Password confirmation:</td>
		<td valign="top"><input name="password2" size="40" type="password"></td>
	</tr>
</table>

<?php
page_section();

page_section("Confirmation");
print "<p>I confirm that I am the bearer of the information stated above. I agree to the board rules, also stated above, and I understand that they may change at any time without notice.</p>\n";
print "<p align=\"center\"><button type=\"submit\">Register</button>\n";
page_section();

print "</form>\n";

page_footer('$Id: page.register.php 115 2007-09-05 23:02:37Z jonathon.keogh $');

?>